﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Data.OleDb;
using System.Data;
using DTO;

namespace DAO
{
    public class DanTocDAO
    {
        public static List<DanTocDTO> LayDanhSach()
        {
            List<DanTocDTO> lstDanToc = new List<DanTocDTO>();
            OleDbConnection cnn = BoKetNoiCSDL.TaoKetNoi();
            string query = "select * from Dan_Toc";
            OleDbCommand cmd = new OleDbCommand(query, cnn);
            cnn.Open();
            try
            {
                OleDbDataReader dr = cmd.ExecuteReader();
                while(dr.Read())
                {
                    DanTocDTO DanTocDto = new DanTocDTO();
                    DanTocDto.MaDanToc = (int)dr["DanTocID"];
                    DanTocDto.TenDanToc = (string)dr["TenDanToc"];
                    lstDanToc.Add(DanTocDto);
                }
            }
            catch
            {
                if (cnn.State == ConnectionState.Open)
                    cnn.Close();
                throw new Exception("thao tác lấy danh sách các dân tộc bị lỗi");
            }
            finally
            {
                cnn.Dispose();
            }
            return lstDanToc;
        }

        public static int Them(DanTocDTO DanTocDto)
        {
            try
            {
                 return 0;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
